package com.scau402.system1.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.scau402.common.annotation.Log;
import com.scau402.common.core.controller.BaseController;
import com.scau402.common.core.domain.AjaxResult;
import com.scau402.common.core.page.TableDataInfo;
import com.scau402.common.enums.BusinessType;
import com.scau402.system1.domain.dto.WmsWarehouseStorageDTO;
import com.scau402.system1.domain.po.WmsWarehouseStoragePO;
import com.scau402.system1.domain.vo.WmsStorageVO;
import com.scau402.system1.domain.vo.WmsWarehouseStorageVO;
import com.scau402.system1.service.impl.WmsWarehouseStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 仓库仓位Controller
 *
 * @author ruoyi
 * @date 2023-06-26
 */
@RestController
@RequestMapping("/system/storage")
public class WmsWarehouseStorageController extends BaseController {
    @Autowired
    private WmsWarehouseStorageService wmsWarehouseStorageService;

    /**
     * 查询仓库仓位列表
     */
    @PreAuthorize("@ss.hasPermi('system:storage:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody WmsWarehouseStorageDTO wmsWarehouseStorageDTO) {
        try (
                Page<Object> page = PageHelper.startPage(
                        wmsWarehouseStorageDTO.getCurrentPage(), wmsWarehouseStorageDTO.getPageSize()
                )
        ) {
            List<WmsStorageVO> list = wmsWarehouseStorageService.list(wmsWarehouseStorageDTO);
            return new TableDataInfo(list, page.getPageNum(), page.getPageSize(), page.getTotal());
        }
    }

    /**
     * 导出仓库仓位列表
     */
    @PreAuthorize("@ss.hasPermi('system:storage:export')")
    @Log(title = "仓库仓位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsWarehouseStoragePO wmsWarehouseStoragePO) {
        throw new UnsupportedOperationException("暂不支持");
    }

    /**
     * 获取仓库仓位详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:storage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        throw new UnsupportedOperationException("暂不支持");
    }

    /**
     * 新增仓库仓位
     */
    @PreAuthorize("@ss.hasPermi('system:storage:add')")
    @Log(title = "仓库仓位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsWarehouseStoragePO wmsWarehouseStoragePO) {
        wmsWarehouseStorageService.insertWmsWarehouseStorage(wmsWarehouseStoragePO);
        return success();
    }

    /**
     * 修改仓库仓位
     */
    @PreAuthorize("@ss.hasPermi('system:storage:edit')")
    @Log(title = "仓库仓位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsWarehouseStoragePO wmsWarehouseStoragePO) {
        wmsWarehouseStorageService.updateWmsWarehouseStorage(wmsWarehouseStoragePO);
        return success();
    }

    /**
     * 删除仓库仓位
     */
    @PreAuthorize("@ss.hasPermi('system:storage:remove')")
    @Log(title = "仓库仓位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        wmsWarehouseStorageService.deleteWmsWarehouseStorageByIds(ids);
        return success();
    }

    /**
     * 获取仓库仓位编码
     *
     * @return
     * @throws InterruptedException
     */
    @PreAuthorize("@ss.hasPermi('system:storage:add')")
    @GetMapping("/getWarehouseStorageCode")
    public String getWarehouseStorageCode() {
        throw new UnsupportedOperationException("暂不知此");
    }

    /**
     * 查询仓库列表
     */
    @PreAuthorize("@ss.hasPermi('system:storage:list')")
    @GetMapping("/listAll")
    public List<WmsWarehouseStorageVO> listAll() {
        return wmsWarehouseStorageService.listAll();
    }


}
